<%--
  Created by IntelliJ IDEA.
  User: 陈杰
  Date: 2020/8/7
  Time: 15:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    /*basePath===http://localhost:8080/TestServlet04/*/
%>
<html>
<head>
    <title>学生课程信息表</title>
    <script type="text/javascript" src="<%=basePath%>static/js/jquery-1.11.3.min.js"></script>

    <link rel="stylesheet" href="<%=basePath%>static/css/bootstrap-theme.css">
    <%--    <link rel="stylesheet" href="<%=basePath%>static/css/pintuer.css">--%>


    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>static/js/jqPaginator.js"></script>
</head>
<body >


    </center>
</div>

    <div style="margin-left: 40%;font-size: larger">
        <span>学生课程信息表</span>
    </div>
<table class="table table-hover" border="1" width="50%">
    <tr>

        <td>教师姓名</td>
<%--        <td>学生姓名</td>--%>
        <td>课程名称</td>
        <td>上课地址</td>
        <td>班级编号</td>
        <td>lstarttime</td>
        <td>iendtime</td>
<%--        <td colspan="1">操作</td>--%>

    </tr>
    <tbody id="tb">
    </tbody>
    <tr>
        <td colspan="8">
            <ul class="pagination" id="pagination1"></ul>
        </td>
    </tr>
</table>
</body>

<script>
    //文档加载后要执行的函数
    $(document).ready(function(){
        loadData();
    });
  /* var total = 0;//总条数
    var totalPages = 0;//总页数
    var visiblePages = 5;//显示的页码数
    var currentPage = 0;//当前页码
    $(document).ready(function(){
        // 第一次访问，初始化全局变量
        showPage(-1);

        $('#pagination1').jqPaginator({
            totalPages: totalPages,
            visiblePages: visiblePages,
            currentPage: currentPage,
            totalCounts: total,
            first: '<li class="first"><a href="javascript:void(0);">第一页</a></li>',
            prev: '<li class="prev"><a href="javascript:void(0);">前一页</a></li>',
            next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
            last: '<li class="last"><a href="javascript:void(0);">最后一页</a></li>',
            page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
            onPageChange: function (num) {
                /!* num代表改变过后的页码 *!/
                showPage(num);
            }
        });
    });

    function showPage(n){
          var sno = $("#sno").val();
           console.log(sno);
        $.ajax({
            url:"<%=basePath%>student/queryLe1",
            async:false,//同步请求（默认）
            type:"POST",
            dataType:"json",
            data:{"pageNum":n,"pageSize":3,"sno":sno},
            success:function(data){
                console.log(data);
                if(n==-1){/!*理解为第一次访问 ，初始化全局变量 *!/
                    total = data.total;
                    totalPages = data.pages;
                    currentPage = data.pageNum;
                }
                $("#tb").html("");
                if(data.list.length>0){
                    //使用jquery形式遍历
                    $.each(data.list,function(n,val){
                        var str = "";
                        str+="<tr>"+
                            "<td>" +  data[n].tname + "</td>" +
                            //
                            "<td>" +  data[n].coursename + "</td>" +
                            "<td>" +  data[n].address + "</td>" +
                            "<td>" +  data[n].cname + "</td>" +
                            "<td>" +  data[n].lstarttime + "</td>" +
                            "<td>" +  data[n].iendtime + "</td>" +
                            "<td><a class=\"btn btn-default\" role=\"button\">删除</a><a class=\"btn btn-default\" role=\"button\" >修改</a></td>"+
                            "</tr>";
                        $("#tb").append(str);
                    });
                }else{
                    $("#tb").append("<tr><td colspan=8 align=\"center\">暂时没有数据哦，快去添加一条吧</td></tr>");
                }
            },
            error:function(){
                alert("服务器出错！");
            }
        });
    }*/

    function loadData() {
        var sno = '<%=session.getAttribute("userId")%>';

        //jquery的ajax请求方法
        $.ajax({
            url: "<%=basePath%>student/queryLe",
            async: false,//同步请求（默认）
            type: "POST",
            dataType: "json",
            data: {"sno":sno},
            success: function (data) {
                console.log(data);
                $("#tb").html("");
                if(data.length>0){
                    //使用jquery形式遍历
                     $.each(data, function (n, val) {
                    var str = "";
                    str += "<tr>" +
                        "<td>" +  data[n].tname + "</td>" +
                        // "<td>" +  data[n].sname + "</td>" +
                        "<td>" +  data[n].coursename + "</td>" +
                        "<td>" +  data[n].address + "</td>" +
                        "<td>" +  data[n].cname + "</td>" +
                        "<td>" +  data[n].lstarttime + "</td>" +
                        "<td>" +  data[n].iendtime + "</td>" +
                        "</tr>";
                    $("#tb").append(str);
                     });
                } else {
                    $("#tb").append("<tr><td colspan=8 align=\"center\">暂时没有数据哦，快去添加一条吧</td></tr>");
                }
            },
            error: function () {
                alert("服务器出错！");
            }
        });
    }

</script>
<%--<script>
    var total = 0;//总条数
    var totalPages = 0;//总页数
    var visiblePages = 5;//显示的页码数
    var currentPage = 0;//当前页码
    $(document).ready(function(){
        /* 第一次访问，初始化全局变量 */
        showPage(-1);

        $('#pagination1').jqPaginator({
            totalPages: totalPages,
            visiblePages: visiblePages,
            currentPage: currentPage,
            totalCounts: total,
            first: '<li class="first"><a href="javascript:void(0);">第一页</a></li>',
            prev: '<li class="prev"><a href="javascript:void(0);">前一页</a></li>',
            next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
            last: '<li class="last"><a href="javascript:void(0);">最后一页</a></li>',
            page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
            onPageChange: function (num) {
                /* num代表改变过后的页码 */
                showPage(num);
            }
        });
    });

    function showPage(n){
        $.ajax({
            url:"<%=basePath%>student/queryLe1",
            async:false,//同步请求（默认）
            type:"POST",
            dataType:"json",
            data:{"pageNum":n,"pageSize":3},
            success:function(data){
                console.log(data);
                if(n==-1){/*理解为第一次访问 ，初始化全局变量 */
                    total = data.total;
                    totalPages = data.pages;
                    currentPage = data.pageNum;
                }
                $("#tb").html("");
                if(data.list.length>0){
                    //使用jquery形式遍历
                    $.each(data.list,function(n,val){
                        var str = "";
                        str+="<tr>"+
                            "<td>" +  val.tname + "</td>" +
                            "<td>" +  val.sname + "</td>" +
                            "<td>" +  val.coursename + "</td>" +
                            "<td>" +  val.address + "</td>" +
                            "<td>" +  val.cname + "</td>" +
                            "<td>" +  val.lstarttime + "</td>" +
                            "<td>" +  val.iendtime + "</td>" +
                            "<td><a class=\"btn btn-default\" role=\"button\">删除</a><a class=\"btn btn-default\" role=\"button\" >修改</a></td>"+
                            "</tr>";
                        $("#tb").append(str);
                    });
                }else{
                    $("#tb").append("<tr><td colspan=8 align=\"center\">暂时没有数据哦，快去添加一条吧</td></tr>");
                }
            },
            error:function(){
                alert("服务器出错！");
            }
        });
    }
</script>--%>
</html>

